package juc.day1;

import lombok.extern.slf4j.Slf4j;

/**
 * Description: 测试打断方法
 *
 * @Autor: Rolin
 * datetime: 09-11-17:03
 */
@Slf4j
public class TestInterrupt {

    private static Thread monitor ;

    public static void main(String[] args) {
        start();
        try {
            Thread.sleep(3500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stop();
    }

    public static void start(){
        monitor = new Thread(()->{
            while (true){
                try {
                    Thread.currentThread().sleep(1000);
                    log.debug("执行监控线程");
                } catch (InterruptedException e) {
                    //如果在睡眠期间被打断，更改打断标记
                    Thread.currentThread().interrupt();
                    e.printStackTrace();
                }
                //总开关出口
                if(monitor.isInterrupted()){
                    log.debug("退出进程前扫尾处理");
                    break;
                }
            }
        });
        monitor.start();

    }
    public static void stop(){
        monitor.interrupt();
    }
}
